<template>
  <div class="system-sensors-add-statusLog">
  <el-dialog v-model="isShowDialog" width="1000px" :close-on-click-modal="false" :destroy-on-close="true">
      <template #header>
        <div v-drag="['.system-sensors-add-statusLog .el-dialog', '.system-sensors-add-statusLog .el-dialog__header']">状态日志</div>
      </template>
    <el-card shadow="hover">
        <el-table v-loading="loading" :data="tableData.data" >
          <el-table-column label="序号" align="center" prop="id"
            min-width="100px"            
             />          
          <el-table-column label="国标id" align="center" prop="linkedDeviceSerial.name"
            min-width="100px"            
             />          
          <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat"
            min-width="100px"            
             />          
          <el-table-column label="创建时间" align="center" prop="createdAt"
            min-width="100px"            
            >
            <template #default="scope">
                <span>{{ proxy.parseTime(scope.row.createdAt, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
            </template>
          </el-table-column>        
        </el-table>
        <pagination
            v-show="tableData.total>0"
            :total="tableData.total"
            v-model:page="tableData.param.pageNum"
            v-model:limit="tableData.param.pageSize"
            @pagination="ys7CameraStatusLogList"
        />
    </el-card>
    </el-dialog>
  </div>
</template>
<script lang="ts">
import {ItemOptions} from "/@/api/items";
import {toRefs, reactive, onMounted, ref, defineComponent, computed,getCurrentInstance,toRaw} from 'vue';
import {ElMessageBox, ElMessage, FormInstance} from 'element-plus';
import {
    listYs7CameraStatusLog,
    delYs7CameraStatusLog,
    listYs7Cameras,    
} from "/@/api/system/ys7CameraStatusLog";
import {
    Ys7CameraStatusLogTableColumns,
    Ys7CameraStatusLogInfoData,
} from "/@/views/system/ys7CameraStatusLog/list/component/model"
export default defineComponent({
    name: "apiV1SystemYs7CameraStatusLogList",
    setup() {
        const {proxy} = <any>getCurrentInstance()
        const loading = ref(false)
        const queryRef = ref()
        const addRef = ref();
        const editRef = ref();
        const detailRef = ref();
        // 是否显示所有搜索选项
        const showAll =  ref(false)
        // 非单个禁用
        const single = ref(true)
        // 非多个禁用
        const multiple =ref(true)
        const word = computed(()=>{
            if(showAll.value === false) {
                //对文字进行处理
                return "展开搜索";
            } else {
                return "收起搜索";
            }
        })
        // 字典选项数据        
        const {            
            online_status,            
        } = proxy.useDict(            
            'online_status',            
        )        
        // deviceSerialOptions关联表数据
        const deviceSerialOptions = ref<Array<ItemOptions>>([])        
        const state = reactive({
            ids:[],isShowDialog:false,
            tableData: {
                data: [],
                total: 0,
                loading: false,
                param: {
                    pageNum: 1,
                    pageSize: 10,                    
                    deviceSerial: undefined,                    
                    status: undefined,                    
                    createdAt: undefined,                    
                    dateRange: []
                },
            },
        });
              // 打开弹窗
    const openDialog = (row:any) => {
      state.isShowDialog=true
      state.tableData.param.deviceSerial=row.deviceSerial
      initTableData();
    };
        // 初始化表格数据
        const initTableData = () => {
            ys7CameraStatusLogList()
        };
        /** 重置按钮操作 */
        const resetQuery = (formEl: FormInstance | undefined) => {
            if (!formEl) return
            formEl.resetFields()
            ys7CameraStatusLogList()
        };
        // 获取列表数据
        const ys7CameraStatusLogList = ()=>{
          loading.value = true
          listYs7CameraStatusLog(state.tableData.param).then((res:any)=>{
            let list = res.data.list??[];            
            state.tableData.data = list;            
            state.tableData.total = res.data.total;
            loading.value = false
          })
        };
        const toggleSearch = () => {
            showAll.value = !showAll.value;
        }        
        //关联ys7_cameras表选项
        const getYs7CamerasItemsDeviceSerial = () => {
          if (deviceSerialOptions.value && deviceSerialOptions.value.length > 0) {
            return
          }
          proxy.getItems(listYs7Cameras, {pageSize:10000}).then((res:any) => {
            deviceSerialOptions.value = proxy.setItems(res, 'deviceSerial', 'name')
          })
        }        
        // 状态字典翻译
        const statusFormat = (row:Ys7CameraStatusLogTableColumns) => {
            return proxy.selectDictLabel(online_status.value, row.status);
        }        
        return {
            proxy,
            addRef,
            editRef,openDialog,
            detailRef,
            showAll,
            loading,
            single,
            multiple,
            word,
            queryRef,
            resetQuery,
            ys7CameraStatusLogList,
            toggleSearch,            
            //关联表数据选项
            deviceSerialOptions,
            //关联ys7_cameras表选项获取数据方法
            getYs7CamerasItemsDeviceSerial,            
            statusFormat,
            online_status,            
            ...toRefs(state),
        }
    }
})
</script>
<style lang="scss" scoped>
    .colBlock {
        display: block;
    }
    .colNone {
        display: none;
    }
</style>